/* 
 * File:   Directory.cpp
 * Author: guilhermemg
 * 
 * Created on 13 de Fevereiro de 2012, 20:51
 */

#include "Directory.h"

Directory::Directory(const char* p) {
    this->setDirectory(p);
    readInDirectory(p);
}

Directory::Directory(const Directory& orig) {
}

Directory::~Directory() {
}

void Directory::setDirectory(const char* p) {
    this->path = p;
}
void Directory::readInDirectory(string path){
    DIR *dp = opendir(path.c_str());
    
   if(dp!=NULL){
        struct dirent *dirp;
        while (dirp = readdir(dp)) {
            if(dirp->d_name[0] == '.')
                    continue;
            string fullPath(path + "/");
            fullPath.append(dirp->d_name);
            readInDirectory(fullPath);
        }
    }else{
        filenames.push_back(path);
    }
    closedir(dp);
}
vector<string> Directory::getFileNames(){
    return filenames;
}
vector<string> Directory::readDirectory() {
    vector<string> names;
    DIR *dp = opendir(path);
    struct dirent *dirp;

    if(dp == NULL) {
         cerr << "Error in opening " << path << endl;
    }

    while (dirp = readdir(dp)) {
        if(dirp->d_name[0] == '.')
                continue;
        names.push_back(dirp->d_name);
    }
    closedir(dp);
    
    return names;
}

